// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Message.java

package cn.sendsms;

import java.util.Date;

// Referenced classes of package cn.sendsms:
//			MessageEncodings, GSMAlphabet, MessageTypes

public class Message
{

	private String gtwId;
	private MessageTypes type;
	private Date date;
	private String id;
	private String text;
	private String encodedText;
	private MessageEncodings encoding;
	protected int pid;
	protected int dcs;

	public Message(MessageTypes type, Date date, String text)
	{
		gtwId = "";
		this.type = type;
		id = "";
		setDate(date);
		this.text = text;
		encoding = MessageEncodings.ENC7BIT;
	}

	public Date getDate()
	{
		return date != null ? new Date(date.getTime()) : null;
	}

	public void setDate(Date date)
	{
		this.date = date == null ? null : new Date(date.getTime());
	}

	public String getEncodedText()
	{
		return encodedText;
	}

	void setEncodedText(String encodedText)
	{
		this.encodedText = encodedText;
	}

	public MessageEncodings getEncoding()
	{
		return encoding;
	}

	public void setEncoding(MessageEncodings encoding)
	{
		this.encoding = encoding;
		if (text == null || text.length() == 0)
			return;
		encodedText = "";
		if (this.encoding == MessageEncodings.ENC7BIT)
			encodedText = GSMAlphabet.textToPDU(text);
		else
		if (this.encoding == MessageEncodings.ENC8BIT)
		{
			byte bytes[] = text.getBytes();
			for (int i = 0; i < bytes.length; i++)
			{
				String s = "0" + Integer.toHexString(bytes[i]);
				int from = s.length() - 2;
				encodedText += s.substring(from);
			}

		} else
		if (this.encoding == MessageEncodings.ENCUCS2)
		{
			for (int i = 0; i < text.length(); i++)
			{
				char c = text.charAt(i);
				int high = c / 256;
				int low = c % 256;
				encodedText += Integer.toHexString(high).length() >= 2 ? Integer.toHexString(high) : "0" + Integer.toHexString(high);
				encodedText += Integer.toHexString(low).length() >= 2 ? Integer.toHexString(low) : "0" + Integer.toHexString(low);
			}

		} else
		if (this.encoding == MessageEncodings.ENCCUSTOM)
			if ((dcs & 4) == 0)
			{
				encodedText = GSMAlphabet.textToPDU(text);
			} else
			{
				for (int i = 0; i < text.length(); i++)
				{
					char c = text.charAt(i);
					encodedText += Integer.toHexString(c).length() >= 2 ? Integer.toHexString(c) : "0" + Integer.toHexString(c);
				}

			}
	}

	public String getGatewayId()
	{
		return gtwId;
	}

	public void setGatewayId(String gtwId)
	{
		this.gtwId = gtwId;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getText()
	{
		return text;
	}

	protected void setText(String text)
	{
		this.text = text;
	}

	void addText(String text)
	{
		this.text += text;
	}

	public MessageTypes getType()
	{
		return type;
	}

	void setType(MessageTypes type)
	{
		this.type = type;
	}
}
